package com.mybatis.controller.shop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mybatis.basic.annotation.rediscache.RedisCache;
import com.mybatis.basic.annotation.rediscache.RedisCacheClear;
import com.mybatis.basic.entity.AjaxJson;
import com.mybatis.entity.shop.GoodsBrand;
import com.mybatis.service.shop.GoodsBrandService;

@Controller
@RequestMapping("/goodsBrand")
public class GoodsBrandController {

	@Autowired
	private GoodsBrandService goodsBrandService;

	//功能主页面
	@RequestMapping("/page")
	public String menuPage(Model model){
		return "goods/goodsbrand/list";
	}

	//分页数据
	@RequestMapping("/pageList")
	@ResponseBody
	@RedisCache(expire = 360, group = "goodsBrand", key = "mydata")
	public AjaxJson pageList(GoodsBrand goodsBrand,Integer page,Integer rows){
		return goodsBrandService.queryListByPage(goodsBrand,page,rows);
	}

	//新增
	@RequestMapping(value = "/manage",method = RequestMethod.POST)
	@ResponseBody
	@RedisCacheClear(group = "goodsBrand", key = "mydata")
	public AjaxJson add(GoodsBrand goodsBrand){
		return goodsBrandService.add(goodsBrand);
	}

	//修改页面
	@RequestMapping(value = "/editPage/{id}", method = RequestMethod.GET)
	public String updatePage(@PathVariable(value = "id") int id,Model model){
		//id为0表示返回新增页面
		if(id!=0){
			model.addAttribute("m",goodsBrandService.queryOne(id).getObj());
		}
		return "goods/goodsbrand/edit";
	}

	//修改
	@RequestMapping(value = "/manage",method = RequestMethod.PUT)
	@ResponseBody
	public AjaxJson update(GoodsBrand goodsBrand,Integer level){
		return goodsBrandService.mod(goodsBrand);
	}

	//删除
	@RequestMapping(value = "/manage/{id}",method = RequestMethod.DELETE)
	@ResponseBody
	public AjaxJson del(@PathVariable(value = "id")int id){
		return goodsBrandService.del(id);
	}
}
